<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="layui-v2.7.6/layui/css/layui.css">
    <script src="./layui-v2.7.6/layui/layui.js"></script>
    <script src="jq/jquery-3.6.4/jquery-3.6.4.min.js"></script>
    <style>
        .mydiv {
            display: none;
        }
    </style>

</head>

<body>

    <div class="mydiv">
        用户名 <input type="text" id="username">
    </div>
    <input type="button" value="打开弹出层" class="layui-btn layui-btn-normal" onclick="doOpen()">

    <script>

        function doOpen() {
            //使用layer模块
            layui.use('layer', function () {
                var layer = layui.layer;
                var index2 = layer.open({
                    title: "用户信息",
                    type: 1,
                    content: $(".mydiv"), //这里content是一个普通的String或者对应的DOM对象的jQuery对象
                    area: ['500px', '500px'],
                    btn: ['保存', '取消']
                    , yes: function (index, layero) {
                        //按钮【按钮一】的回调
                        console.log(11);
                        // layer.close(index);//关闭指定打开的弹出层
                        layer.closeAll();//关闭所有层
                        $(".mydiv").css("display", "none");
                    }
                    , btn2: function (index, layero) {
                        //按钮【按钮二】的回调
                        $(".mydiv").css("display", "none");
                        // return false //开启该代码可禁止点击该按钮关闭
                    }
                    , cancel: function () {
                        //右上角关闭回调

                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
            });


           
        }



    </script>

</body>



</html>